package service.impl;

import mapper.ForumMapper;
import org.springframework.stereotype.Service;
import pojo.ForumInvitation;
import service.FromService;
import tools.PageInvitation;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 14201 on 2019/2/20.
 */
@Service("FromService")
public class ForumServiceimpl implements FromService {
    @Resource
    ForumMapper forumMapper;


    public PageInvitation getForumList(Integer id, String title, PageInvitation pageObj) {
        // 查询总条数
        int totalCount = forumMapper.getCount(id,title);
        // 设置总数、总页数
        pageObj.setTotalCount(totalCount);
        // 如果总条数>0,说明数据库中有数据，再查询具体数据
        if (totalCount > 0) {
            // （用户一直点击下一页）如果当前页大于总页数，把总页数的值赋给当前页的值，显示最后一页的值
            if (pageObj.getCurrPageNo() > pageObj.getTotalPageCount())
                pageObj.setCurrPageNo(pageObj.getTotalPageCount());
            List<ForumInvitation> lrsList = forumMapper.getForumList(id,title,(pageObj.getCurrPageNo()-1)*pageObj.getPageSize(), pageObj.getPageSize());
            System.out.println(lrsList.size()
            );
            pageObj.setList(lrsList);
        } else {
            pageObj.setCurrPageNo(0);
            pageObj.setList(new ArrayList<ForumInvitation>());
        }
        return pageObj;
    }
}
